#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;

const int NMAX = 100;

ifstream fin("G3.txt");

vector<int> a[NMAX];
int n;
int vis[100];
int d[NMAX];
int pr[NMAX];


void init()
{ int m;
  fin >> n >> m;
  
  for(int i=0; i<m; i++)
  { int u,v;
    fin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
}

void bfs(int s)
{ for(int u=1; u<=n; u++)
    vis[u]=0;
    
  queue<int> q;
  q.push(s); vis[s]=1;
  
  d[s]=0; pr[s]=0;
  
  while(q.size()>0)
  { int u = q.front(); q.pop();
//    cout << u << " ";
    int k=a[u].size();
    for(int i=0; i<k; i++)
    { int v = a[u][i];
      if(vis[v]==0)
      { q.push(v); vis[v]=1; 
        d[v]=d[u]+1;
        pr[v]=u;
      }
    }
  }
//  cout << endl;
}

int main()
{ init();
  int s,t;
  cout << "s = ";
  cin >> s;   
  cout << "t = ";
  cin >> t;   
  bfs(s);    
  cout << "Distance from " << s << " to " 
       << t << " is " << d[t] << endl; 
  return 0;
}
